<!DOCTYPE html>
<html xmlns:fb="http://www.facebook.com/2008/fbml" lang="en">

<head>
	<meta charset="utf-8" />
	<title>Testing The RSVP button</title>
	<meta name="generator" content="BBEdit 10.0" />
</head>
<body>

<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js" charset="utf-8"></script>

<script> 
	FB.init({appId:'384714264881936', status: true, cookie:true, xfbml:true});
</script>
<h1>Test the Rsvp to the Whole Foods Event  </h1>

<div id="quote"> 
	<div id="auth"></div>
</div>

<script> 

FB.getLoginStatus(function(response) {
  if (response.status === 'connected') {
    // the user is logged in and connected to your
    // app, and response.authResponse supplies
    // the user’s ID, a valid access token, a signed
    // request, and the time the access token 
    // and signed request each expire
    var uid = response.authResponse.userID;
    var accessToken = response.authResponse.accessToken;
    FB.api('/me', function(response) 
     {
     	document.getElementById('auth').innerHTML = 'Good to see you, ' + response.name + '.';
       //console.log('Good to see you, ' + response.name + '.');
     });
    console.log("connected: " + uid + ", " + accessToken);
  } else if (response.status === 'not_authorized') {
  	login();
    // the user is logged in to Facebook, 
    //but not connected to the app
  } else {
    // the user isn't even logged in to Facebook.
    login();
  }
});

function login()
{
 FB.login(function(response) 
 {
   if (response.authResponse) 
   {
     //console.log('Welcome!  Fetching your information.... ');
     FB.api('/me', function(response) 
     {
     	document.getElementById('auth').innerHTML = 'Good to see you, ' + response.name + '.';
       //console.log('Good to see you, ' + response.name + '.');
     });
   } else {
     console.log('User cancelled login or did not fully authorize.');
   }
 }, {scope:'publish_stream,rsvp_event'});
}

function test()
{
	FB.api('/375130929193203/attending',"post",
	function(response) {
		if (!response || response.error) {
			alert("We're sorry, there was an error connecting with Facebook. Please try again.");
		} else {
			alert("You've successfully RSVPd to the event!");
		}
	});
}

</script>			
<a href="#" onclick="test()">RSVP </a>

</body>
</html>
